﻿using RayDen.RayEngine.Core;
using RayDen.RayEngine.Core.Devices;
using RayDen.RayEngine.Core.Interface;
using RayDen.RayEngine.Core.Threads;
using RayDen.RayEngine.Managers;

namespace RayDen.RayEngine.Engines.MCMC {

    public class DeviceRenderThread : DeviceRenderThread<MCMCPathBuffer>
    {
        public DeviceRenderThread(int index,
                                  IIntersectionEngine device,
                                  RayEngineScene scn,
                                  bool lowLatency,
                                  ImageFilmBase pixelDevice,
                                  SamplingContext sc, IFrameManager frameManager)
            : base(index, device, scn, lowLatency, pixelDevice, sc, frameManager) { }
    }

    public class MCMCPathTracerEngine : BaseRenderingEngine {
        public MCMCPathTracerEngine(RayEngineScene scene) : base(scene) { }

        public override RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice, RayEngineScene scene, IImageFilm film, IFrameManager frameManager, SamplingContext samplingContext)
        {
            return new DeviceRenderThread(threadIndex, intersectionDevice, scene, LowLatencySampling, (MCMCImageFilm)film, samplingContext , frameManager);
        }

        public override ISampler CreateSampler(int width, int height, int maxPathDepth, int threadIndex, int screenStartLine, int windowHeight) {
            //var sampler = new UniformSampler() { lowLatency = LowLatencySampling , tIdx = threadIndex, screenStartLine = screenStartLine};
            //var sampler = new RandomSampler() { lowLatency = LowLatencySampling, tIdx = threadIndex, screenStartLine = screenStartLine };
            var sampler = new MarkovChainSampler() { lowLatency = LowLatencySampling, sceneMaxPathDepth = maxPathDepth, screenHeight = height, screenWidth = width, screenStartLine = screenStartLine};
            //var sampler = new MCMCSampler() { lowLatency = LowLatencySampling, sceneMaxPathDepth = maxPathDepth, screenHeight = height, screenWidth = width, screenStartLine = screenStartLine };

            return sampler;
        }

        public override string GetEngineStats()
        {
            return base.GetEngineStats();
        }

        public override Core.Interface.IImageFilm CreateFilm(int width, int height) {
            return new MCMCImageFilm(width, height);
        }
    }

}